<?php
namespace app\modules\content\models;

use yii\db\ActiveRecord;
use yii;

class Examroom extends ActiveRecord
{
    public static function tableName()
    {
        return '{{%examination}}';
    }

    public function rules()
    {
        return [
            // username and password are both required
            [['name'], 'required'],

        ];
    }

    public static function getExamroom($area)
    {
        if($area==false){
            $city = Examroom::find()->distinct()->select('city')->asArray()->all();
        }else{
            $city = Examroom::find()->distinct()->select('city')->asArray()->where('area=' . $area)->all();
        }
        $data=array();
        foreach ($city as $k => $v) {
            $data[$k]= Examroom::find()->asArray()->where('city="' . $v['city'].'"')->all();
        }
        return $data;
    }


    /**
     * [getExamroomByArea 根据区域查询考点]
     * @Author don
     * @Date   2021-10-27
     * @param  [type]     $area [description]
     * @return [type]           [description]
     */
    public static function getExamroomByArea($area)
    {
        $data = [];
        // 考试地点默认展示“全部”内容（目前只有上海一个考点），“全部”和“华东”点击后显示上海，其他都为空状态
        if ($area == 0) {
            $city = Examroom::find()->distinct()->select('city')->asArray()->all();
        } else {
            $city = Examroom::find()->distinct()->select('city')->where('area='.$area)->asArray()->all();
        }
        foreach ($city as $key => $value) {
            $data[$key]['cityName'] = $value['city'];
            // 查询考点背景图
            $examImage = ExamroomImage::find()->where(['city'=>$value['city']])->asArray()->one();
            $data[$key]['pic'] = $examImage?"https://www.thinkuprep.com".$examImage['pic']:null;
            $data[$key]['data'] = Examroom::find()->where('city="' . $value['city'].'"')->asArray()->all();
            foreach ($data[$key]['data'] as $k2=>$v2){
                if(!empty($v2['pic'])){
                    $data[$key]['data'][$k2]['pic'] = "https://www.thinkuprep.com".$v2['pic'];
                }
            }
        }
        return $data;
    }

    /**
     * [getExamroomByCity 根据城市获取考点列表详情]
     * @Author don
     * @Date   2021-10-27
     * @param  [type]     $city [description]
     * @return [type]           [description]
     */
    public static function getExamroomByCity($city)
    {
        $data = Examroom::find()->where('city="' . $city.'"')->asArray()->all();

        return $data;
    }
}